<?php
//提供command line操作
require_once __DIR__.'/Manager.php';
Manager::init();

$map = array(
    'Manager' => 'Manager',
    'Config' => 'Config',
    'Arr' => 'Arr',
    'ErrorManager' => 'ErrorManager',
);

$parseArgs = function(array &$args)
{
    foreach ($args as &$arg)
    {
        if (preg_match('/^\[[^\[\]]*\]$/', $arg))
        {
            $arg = Arr::parse($arg);
        }
        else if (preg_match('/^true$/i', $arg))
        {
            $arg = true;
        }
        else if (preg_match('/^false$/i', $arg))
        {
            $arg = false;
        }
        else if (preg_match('/^null$/i', $arg))
        {
            $arg = null;
        }
    }
};

$params = array_slice($_SERVER['argv'], 1);
$parseArgs($params);
$classname = current(array_splice($params, 0, 1));
$method = current(array_splice($params, 0, 1));

if (isset($map[$classname]) && class_exists($map[$classname]))
{
    $class_namespace = $map[$classname];
    if ($method && is_callable("{$class_namespace}::{$method}"))
    {
        var_dump(call_user_func_array("{$class_namespace}::{$method}", $params));
        die;
    }
    else 
    {
        die("{$class_namespace}沒有{$method}方法");
    }
}
die("找不到class[{$classname}]");